feat(profile-sync-controller): add authentication selectors for cached session data#9604
Open
baptiste-marchand wants to merge 3 commits into
Open
feat(profile-sync-controller): add authentication selectors for cached session data#9604baptiste-marchand wants to merge 3 commits into
baptiste-marchand wants to merge 3 commits into
Conversation
baptiste-marchand
temporarily deployed
to
default-branch
July 22, 2026 14:45 — with
GitHub Actions
Inactive
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Clients (especially mobile Braze banners) need a sync way to read the cached
canonicalProfileIdfor identity (Braze.changeUser) before refreshing banners. Today the shared path isAuthenticationController.getSessionProfile(), which can take 2s+ when it falls into a re-login / unlock-gated path — too slow for this use case.Cached
canonicalProfileIdin persistedsrpSessionDatais enough for Braze (best-effort identity; canonical rarely changes between sessions). Mobile currently has a temporary client-side helper; Core should own this as the shared source of truth.This PR adds guideline-aligned derived-state selectors on
AuthenticationController(no new state field, no getter, no messenger action):selectSrpSessionData— rawsrpSessionDatamapselectSessionData— primary / first SRP session entry (same convention as extension)selectCanonicalProfileId— cached canonical ID; treats''as missing (controller invalidation marker)Exported from
@metamask/profile-sync-controller/auth. Staleness matches a valid cachedgetSessionProfile(); userefreshCanonicalProfileId()when freshness is required. Existing auth APIs are unchanged.References
Checklist
Note
Low Risk
Read-only derived selectors with no auth flow changes; main caveat is documented cache staleness for identity use cases.
Overview
Adds
authenticationControllerSelectorsonAuthenticationControllerso clients can read cached session identity synchronously from persisted state instead of callinggetSessionProfile()(which can block on unlock/re-login).New selectors:
selectSrpSessionData(raw map),selectSessionData(first/primary SRP entry, same convention as extension), andselectCanonicalProfileId(best-effort canonical ID; treats''as missing to match#invalidateSrpSession). Exported from the auth package entrypoint; no new state, messenger actions, or changes to existing auth APIs.Docs note the same staleness as a valid cached session and point consumers that need freshness at
refreshCanonicalProfileId(). Unit tests cover empty/missing session data and multi-SRP cases.Reviewed by Cursor Bugbot for commit 064aea9. Bugbot is set up for automated code reviews on this repo. Configure here.